//
//  TabBarControl.m
//  OCweibo
//
//  Created by 郑兆远 on 15/12/21.
//  Copyright © 2015年 zzy. All rights reserved.
//

#import "TabBarControl.h"
#import "TabBarView.h"
#import "HomeViewController.h"
#import "DiscoveryViewController.h"
#import "MessageViewController.h"
#import "ProfileViewController.h"

@interface TabBarControl ()
@property (nonatomic,strong)TabBarView *myTabBar;
@end

@implementation TabBarControl

- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self loadChildController];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self setValue:self.myTabBar forKey:@"tabBar"];
}
- (TabBarView *)myTabBar{
    if (!_myTabBar) {
        _myTabBar = [[TabBarView alloc]init];
        [_myTabBar.composeBtn addTarget:self action:@selector(composeBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _myTabBar;
}
- (void)composeBtnDidClick{
    NSLog(@"%s",__func__);
}


- (void)loadChildController{
    HomeViewController *homeVC = [[HomeViewController alloc]init];
    MessageViewController *messVC = [[MessageViewController alloc]init];
    DiscoveryViewController *discVC = [[DiscoveryViewController alloc]init];
    ProfileViewController *profVC = [[ProfileViewController alloc]init];
    [self loadChildControllers:homeVC controlName:@"首页" imageName:@"tabbar_home"];
    [self loadChildControllers:messVC controlName:@"消息" imageName:@"tabbar_message_center"];
    [self loadChildControllers:discVC controlName:@"发现" imageName:@"tabbar_discover"];
    [self loadChildControllers:profVC controlName:@"我" imageName:@"tabbar_profile"];
}
- (void)loadChildControllers:(UIViewController *)VC  controlName:(NSString *)name imageName:(NSString *)imageName {
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:VC];
    VC.title = name;
    VC.tabBarItem.image = [UIImage imageNamed:imageName];
    [self addChildViewController:nav];
}

@end
